namespace QMVnSoft.Invoices
{
    using QMVnSoft;
    using QMVnSoft.Controls;
    using QMVnSoft.Controls.ChildGridControls;
    using QMVnSoft.DAL;
    using System;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Windows.Forms;

    public class FormCTKHOLister : FormLister
    {
        private StatusColumn Column1;
        private StatusColumn Column2;
        private DataGridViewTextBoxColumn Column3;
        private DataGridViewTextBoxColumn Column4;
        private DataGridViewTextBoxColumn Column5;
        private DataGridViewTextBoxColumn Column6;
        private DataGridViewTextBoxColumn Column7;
        private DataGridViewTextBoxColumn Column8;
        private IContainer components;
        private GridControl grdDetail;
        private GridControl grdMaster;
        private SplitContainer GridContainer;
        private object id_Ngay_Ct1;
        private object id_Ngay_Ct2;
        private int ii_FilterByUser;
        private int ii_Locked;
        private int ii_Posted;
        private object is_Dien_Giai;
        private object is_Ghi_Chu;
        private object is_Ma_Dt;
        private object is_Ma_Kho;
        private object is_Ma_Loai1;
        private object is_Ma_Loai2;
        private object is_Ma_Loai3;
        private object is_Ma_Vt;
        private object is_So_Ct1;
        private object is_So_Ct2;
        private DataTable oCanNotDelete;
        private DataGridViewTextBoxColumn Column9;
        private DataGridViewTextBoxColumn Column10;
        private DataGridViewTextBoxColumn Column11;
        private DataGridViewTextBoxColumn Column12;
        private DataGridViewTextBoxColumn Column13;
        private DataGridViewTextBoxColumn Column17;
        private DataGridViewTextBoxColumn Column18;
        private NumericColumn Column19;
        private NumericColumn Column20;
        private NumericColumn Column21;
        private DataGridViewTextBoxColumn Column14;
        private DataGridViewTextBoxColumn Column23;
        private NumericColumn Column22;
        private CTKHODataAccess oMethod;

        public FormCTKHOLister()
        {
            this.oMethod = new CTKHODataAccess();
            this.id_Ngay_Ct1 = DBNull.Value;
            this.id_Ngay_Ct2 = DBNull.Value;
            this.is_So_Ct1 = DBNull.Value;
            this.is_So_Ct2 = DBNull.Value;
            this.is_Ma_Dt = DBNull.Value;
            this.is_Ma_Kho = DBNull.Value;
            this.is_Ma_Vt = DBNull.Value;
            this.is_Dien_Giai = DBNull.Value;
            this.is_Ghi_Chu = DBNull.Value;
            this.is_Ma_Loai1 = DBNull.Value;
            this.is_Ma_Loai2 = DBNull.Value;
            this.is_Ma_Loai3 = DBNull.Value;
            this.ii_FilterByUser = AppInstance.FilterByUser ? 1 : 0;
            this.InitializeComponent();
            base.MasterGridBrowser = this.grdMaster;
            base.DetailGridBrowser = this.grdDetail;
            (base.MasterGridBrowser.Columns[0] as StatusColumn).StatusField = 0;
            (base.MasterGridBrowser.Columns[1] as StatusColumn).StatusField = 1;
            this.OnResetControls();
            base.ResizeForm();
        }

        public FormCTKHOLister(string ps_InvoiceCode)
        {
            this.oMethod = new CTKHODataAccess();
            this.id_Ngay_Ct1 = DBNull.Value;
            this.id_Ngay_Ct2 = DBNull.Value;
            this.is_So_Ct1 = DBNull.Value;
            this.is_So_Ct2 = DBNull.Value;
            this.is_Ma_Dt = DBNull.Value;
            this.is_Ma_Kho = DBNull.Value;
            this.is_Ma_Vt = DBNull.Value;
            this.is_Dien_Giai = DBNull.Value;
            this.is_Ghi_Chu = DBNull.Value;
            this.is_Ma_Loai1 = DBNull.Value;
            this.is_Ma_Loai2 = DBNull.Value;
            this.is_Ma_Loai3 = DBNull.Value;
            this.ii_FilterByUser = AppInstance.FilterByUser ? 1 : 0;
            this.InitializeComponent();
            base.InvoiceCode = ps_InvoiceCode;
            base.MasterGridBrowser = this.grdMaster;
            base.DetailGridBrowser = this.grdDetail;
            (base.MasterGridBrowser.Columns[0] as StatusColumn).StatusField = 0;
            (base.MasterGridBrowser.Columns[1] as StatusColumn).StatusField = 1;
            this.OnResetControls();
            base.ResizeForm();
        }

        private void AddNotDeleteInvoice(object pd_Ngay_Ct, object ps_So_Ct, object ps_Dien_Giai)
        {
            if (this.oCanNotDelete == null)
            {
                this.oCanNotDelete = new DataTable();
                this.oCanNotDelete.Columns.Add("Ngay_Ct", typeof(DateTime));
                this.oCanNotDelete.Columns.Add("So_Ct", typeof(string));
                this.oCanNotDelete.Columns.Add("Dien_Giai", typeof(string));
            }
            DataRow row = this.oCanNotDelete.NewRow();
            row["Ngay_Ct"] = pd_Ngay_Ct;
            row["So_Ct"] = ps_So_Ct;
            row["Dien_Giai"] = ps_Dien_Giai;
            this.oCanNotDelete.Rows.Add(row);
        }

        private bool CheckInvoiceLock(object ps_InvoiceOrder, bool pb_Locked)
        {
            string str = null;
            if (!this.CheckInvoiceLock(ps_InvoiceOrder, pb_Locked, ref str))
            {
                MessageBox.Show(str, AppInstance.SoftwareName, MessageBoxButtons.OK, MessageBoxIcon.Hand);
                return false;
            }
            return true;
        }

        private bool CheckInvoiceLock(object ps_InvoiceOrder, bool pb_Locked, ref string ps_WarningMessage)
        {
            int num = this.oMethod.CheckInvoiceLock(AppInstance.Subsidiary, AppInstance.UserName, ps_InvoiceOrder);
            if (((num == 7) || ((num == 5) && pb_Locked)) || ((num == 2) && !pb_Locked))
            {
                ps_WarningMessage = base.AppInvoiceParameters.LockedMessage(num, pb_Locked);
                return false;
            }
            this.oMethod.Lock(AppInstance.UserName, ps_InvoiceOrder, pb_Locked);
            return true;
        }

        private bool CheckInvoicePost(object ps_InvoiceOrder, int pi_Posted)
        {
            string str = null;
            int num = 0;
            if (this.CheckInvoicePost(ps_InvoiceOrder, pi_Posted, ref str, ref num))
            {
                return true;
            }
            if (num == 8)
            {
                base.AppInvoiceParameters.ShowInvoiceUsed(ps_InvoiceOrder, str);
            }
            else
            {
                MessageBox.Show(str, AppInstance.SoftwareName, MessageBoxButtons.OK, MessageBoxIcon.Hand);
            }
            return false;
        }

        private bool CheckInvoicePost(object ps_InvoiceOrder, int pi_Posted, ref string ps_WarningMessage, ref int pi_Result)
        {
            pi_Result = this.oMethod.CheckInvoicePost(AppInstance.Subsidiary, AppInstance.UserName, ps_InvoiceOrder);
            if (((((pi_Result == 9) || (pi_Result == 8)) || (pi_Result == 7)) || ((pi_Result == 6) && (pi_Posted == 2))) || ((pi_Result == 3) && (pi_Posted == 0)))
            {
                ps_WarningMessage = base.AppInvoiceParameters.PostedMessage(pi_Result, pi_Posted);
                return false;
            }
            this.oMethod.Post(AppInstance.UserName, ps_InvoiceOrder, pi_Posted);
            return true;
        }

        private bool CheckInvoiceStatus(object ps_InvoiceOrder)
        {
            string str = null;
            int num = 0;
            if (this.CheckInvoiceStatus(ps_InvoiceOrder, ref str, ref num))
            {
                return true;
            }
            if (num == 8)
            {
                base.AppInvoiceParameters.ShowInvoiceUsed(ps_InvoiceOrder, str);
            }
            else
            {
                MessageBox.Show(str, AppInstance.SoftwareName, MessageBoxButtons.OK, MessageBoxIcon.Hand);
            }
            return false;
        }

        private bool CheckInvoiceStatus(object ps_InvoiceOrder, ref string ps_WarningMessage, ref int pi_Result)
        {
            pi_Result = this.oMethod.CheckInvoiceStatus(AppInstance.Subsidiary, AppInstance.UserName, ps_InvoiceOrder);
            if (((pi_Result != 9) && (pi_Result != 8)) && (((pi_Result != 7) && (pi_Result != 6)) && (pi_Result != 5)))
            {
                return true;
            }
            ps_WarningMessage = base.AppInvoiceParameters.StatusMessage(pi_Result);
            return false;
        }

        protected override void Dispose(bool disposing)
        {
            if (disposing && (this.components != null))
            {
                this.components.Dispose();
            }
            base.Dispose(disposing);
        }

        private void InitializeComponent()
        {
            System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle1 = new System.Windows.Forms.DataGridViewCellStyle();
            System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle2 = new System.Windows.Forms.DataGridViewCellStyle();
            System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle3 = new System.Windows.Forms.DataGridViewCellStyle();
            System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle4 = new System.Windows.Forms.DataGridViewCellStyle();
            System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle5 = new System.Windows.Forms.DataGridViewCellStyle();
            System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle6 = new System.Windows.Forms.DataGridViewCellStyle();
            this.GridContainer = new System.Windows.Forms.SplitContainer();
            this.grdMaster = new QMVnSoft.Controls.GridControl();
            this.Column1 = new QMVnSoft.Controls.ChildGridControls.StatusColumn();
            this.Column2 = new QMVnSoft.Controls.ChildGridControls.StatusColumn();
            this.Column3 = new System.Windows.Forms.DataGridViewTextBoxColumn();
            this.Column4 = new System.Windows.Forms.DataGridViewTextBoxColumn();
            this.Column5 = new System.Windows.Forms.DataGridViewTextBoxColumn();
            this.Column6 = new System.Windows.Forms.DataGridViewTextBoxColumn();
            this.Column7 = new System.Windows.Forms.DataGridViewTextBoxColumn();
            this.Column8 = new System.Windows.Forms.DataGridViewTextBoxColumn();
            this.grdDetail = new QMVnSoft.Controls.GridControl();
            this.Column9 = new System.Windows.Forms.DataGridViewTextBoxColumn();
            this.Column10 = new System.Windows.Forms.DataGridViewTextBoxColumn();
            this.Column11 = new System.Windows.Forms.DataGridViewTextBoxColumn();
            this.Column12 = new System.Windows.Forms.DataGridViewTextBoxColumn();
            this.Column13 = new System.Windows.Forms.DataGridViewTextBoxColumn();
            this.Column17 = new System.Windows.Forms.DataGridViewTextBoxColumn();
            this.Column18 = new System.Windows.Forms.DataGridViewTextBoxColumn();
            this.Column19 = new QMVnSoft.Controls.ChildGridControls.NumericColumn();
            this.Column20 = new QMVnSoft.Controls.ChildGridControls.NumericColumn();
            this.Column21 = new QMVnSoft.Controls.ChildGridControls.NumericColumn();
            this.Column14 = new System.Windows.Forms.DataGridViewTextBoxColumn();
            this.Column23 = new System.Windows.Forms.DataGridViewTextBoxColumn();
            this.Column22 = new QMVnSoft.Controls.ChildGridControls.NumericColumn();
            this.GridContainer.Panel1.SuspendLayout();
            this.GridContainer.Panel2.SuspendLayout();
            this.GridContainer.SuspendLayout();
            ((System.ComponentModel.ISupportInitialize)(this.grdMaster)).BeginInit();
            ((System.ComponentModel.ISupportInitialize)(this.grdDetail)).BeginInit();
            this.SuspendLayout();
            // 
            // GridContainer
            // 
            this.GridContainer.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
                        | System.Windows.Forms.AnchorStyles.Left)
                        | System.Windows.Forms.AnchorStyles.Right)));
            this.GridContainer.IsSplitterFixed = true;
            this.GridContainer.Location = new System.Drawing.Point(0, 24);
            this.GridContainer.Name = "GridContainer";
            this.GridContainer.Orientation = System.Windows.Forms.Orientation.Horizontal;
            // 
            // GridContainer.Panel1
            // 
            this.GridContainer.Panel1.Controls.Add(this.grdMaster);
            // 
            // GridContainer.Panel2
            // 
            this.GridContainer.Panel2.Controls.Add(this.grdDetail);
            this.GridContainer.Size = new System.Drawing.Size(794, 483);
            this.GridContainer.SplitterDistance = 227;
            this.GridContainer.SplitterWidth = 1;
            this.GridContainer.TabIndex = 13;
            // 
            // grdMaster
            // 
            this.grdMaster.AllowUserToAddRows = false;
            this.grdMaster.AllowUserToDeleteRows = false;
            this.grdMaster.CheckAutoSize = true;
            this.grdMaster.CheckColor = false;
            this.grdMaster.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
            this.grdMaster.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] {
            this.Column1,
            this.Column2,
            this.Column3,
            this.Column4,
            this.Column5,
            this.Column6,
            this.Column7,
            this.Column8});
            this.grdMaster.Dock = System.Windows.Forms.DockStyle.Fill;
            this.grdMaster.Font = new System.Drawing.Font("Arial", 8.25F);
            this.grdMaster.Location = new System.Drawing.Point(0, 0);
            this.grdMaster.Name = "grdMaster";
            this.grdMaster.ReadOnly = true;
            this.grdMaster.Size = new System.Drawing.Size(794, 227);
            this.grdMaster.TabIndex = 0;
            // 
            // Column1
            // 
            this.Column1.DataPropertyName = "Locked";
            dataGridViewCellStyle1.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleCenter;
            this.Column1.DefaultCellStyle = dataGridViewCellStyle1;
            this.Column1.HeaderText = "";
            this.Column1.Name = "Column1";
            this.Column1.ReadOnly = true;
            this.Column1.Resizable = System.Windows.Forms.DataGridViewTriState.False;
            this.Column1.StatusField = 0;
            this.Column1.Width = 22;
            // 
            // Column2
            // 
            this.Column2.DataPropertyName = "Posted";
            dataGridViewCellStyle2.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleCenter;
            this.Column2.DefaultCellStyle = dataGridViewCellStyle2;
            this.Column2.HeaderText = "";
            this.Column2.Name = "Column2";
            this.Column2.ReadOnly = true;
            this.Column2.Resizable = System.Windows.Forms.DataGridViewTriState.False;
            this.Column2.StatusField = 0;
            this.Column2.Width = 22;
            // 
            // Column3
            // 
            this.Column3.DataPropertyName = "Ngay_Ct";
            this.Column3.HeaderText = "Ngày";
            this.Column3.Name = "Column3";
            this.Column3.ReadOnly = true;
            this.Column3.Resizable = System.Windows.Forms.DataGridViewTriState.False;
            this.Column3.Width = 62;
            // 
            // Column4
            // 
            this.Column4.DataPropertyName = "So_Ct";
            this.Column4.HeaderText = "Số";
            this.Column4.Name = "Column4";
            this.Column4.ReadOnly = true;
            this.Column4.Width = 70;
            // 
            // Column5
            // 
            this.Column5.DataPropertyName = "Dien_Giai";
            this.Column5.HeaderText = "Diễn giải (VN)";
            this.Column5.Name = "Column5";
            this.Column5.ReadOnly = true;
            this.Column5.Width = 146;
            // 
            // Column6
            // 
            this.Column6.DataPropertyName = "Desc_EN";
            this.Column6.HeaderText = "Diễn giải (EN)";
            this.Column6.Name = "Column6";
            this.Column6.ReadOnly = true;
            this.Column6.Width = 145;
            // 
            // Column7
            // 
            this.Column7.DataPropertyName = "Ghi_Chu";
            this.Column7.HeaderText = "Ghi chú";
            this.Column7.Name = "Column7";
            this.Column7.ReadOnly = true;
            this.Column7.Width = 142;
            // 
            // Column8
            // 
            this.Column8.DataPropertyName = "Ten_KhoN";
            this.Column8.HeaderText = "Kho nhập";
            this.Column8.Name = "Column8";
            this.Column8.ReadOnly = true;
            this.Column8.Resizable = System.Windows.Forms.DataGridViewTriState.True;
            this.Column8.Width = 142;
            // 
            // grdDetail
            // 
            this.grdDetail.AllowUserToAddRows = false;
            this.grdDetail.AllowUserToDeleteRows = false;
            this.grdDetail.CheckAutoSize = true;
            this.grdDetail.CheckColor = false;
            this.grdDetail.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
            this.grdDetail.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] {
            this.Column9,
            this.Column10,
            this.Column11,
            this.Column12,
            this.Column13,
            this.Column17,
            this.Column18,
            this.Column19,
            this.Column20,
            this.Column21,
            this.Column14,
            this.Column23,
            this.Column22});
            this.grdDetail.Dock = System.Windows.Forms.DockStyle.Fill;
            this.grdDetail.Font = new System.Drawing.Font("Arial", 8.25F);
            this.grdDetail.Location = new System.Drawing.Point(0, 0);
            this.grdDetail.Name = "grdDetail";
            this.grdDetail.Size = new System.Drawing.Size(794, 255);
            this.grdDetail.TabIndex = 0;
            // 
            // Column9
            // 
            this.Column9.DataPropertyName = "Ma_Vt";
            this.Column9.HeaderText = "Mã vật tư";
            this.Column9.MinimumWidth = 90;
            this.Column9.Name = "Column9";
            this.Column9.ReadOnly = true;
            this.Column9.Width = 90;
            // 
            // Column10
            // 
            this.Column10.DataPropertyName = "Ten_Vt";
            this.Column10.HeaderText = "Tên vật tư";
            this.Column10.MinimumWidth = 120;
            this.Column10.Name = "Column10";
            this.Column10.ReadOnly = true;
            this.Column10.Width = 120;
            // 
            // Column11
            // 
            this.Column11.DataPropertyName = "Dvt";
            this.Column11.HeaderText = "Đvt";
            this.Column11.MinimumWidth = 40;
            this.Column11.Name = "Column11";
            this.Column11.ReadOnly = true;
            this.Column11.Width = 40;
            // 
            // Column12
            // 
            this.Column12.DataPropertyName = "Ma_Kho";
            this.Column12.HeaderText = "Kho";
            this.Column12.MinimumWidth = 50;
            this.Column12.Name = "Column12";
            this.Column12.ReadOnly = true;
            this.Column12.Width = 50;
            // 
            // Column13
            // 
            this.Column13.HeaderText = "Kệ hàng";
            this.Column13.MinimumWidth = 50;
            this.Column13.Name = "Column13";
            this.Column13.ReadOnly = true;
            this.Column13.Width = 50;
            // 
            // Column17
            // 
            this.Column17.DataPropertyName = "Lo_Hang";
            this.Column17.HeaderText = "Lô hàng";
            this.Column17.MinimumWidth = 70;
            this.Column17.Name = "Column17";
            this.Column17.ReadOnly = true;
            this.Column17.Width = 70;
            // 
            // Column18
            // 
            this.Column18.DataPropertyName = "Han_Dung";
            this.Column18.HeaderText = "Hạn dùng";
            this.Column18.MinimumWidth = 70;
            this.Column18.Name = "Column18";
            this.Column18.ReadOnly = true;
            this.Column18.Resizable = System.Windows.Forms.DataGridViewTriState.False;
            this.Column18.Width = 70;
            // 
            // Column19
            // 
            this.Column19.DataPropertyName = "H_Luong";
            dataGridViewCellStyle3.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleRight;
            this.Column19.DefaultCellStyle = dataGridViewCellStyle3;
            this.Column19.HeaderText = "Hàm lượng";
            this.Column19.MinimumWidth = 60;
            this.Column19.Name = "Column19";
            this.Column19.ReadOnly = true;
            this.Column19.SortMode = System.Windows.Forms.DataGridViewColumnSortMode.Automatic;
            this.Column19.UserTextNumericFormat = QMVnSoft.AppInstance.TextNumericFormat.Percent;
            this.Column19.Width = 60;
            // 
            // Column20
            // 
            this.Column20.DataPropertyName = "Do_Am_PT";
            dataGridViewCellStyle4.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleRight;
            this.Column20.DefaultCellStyle = dataGridViewCellStyle4;
            this.Column20.HeaderText = "Độ ẩm";
            this.Column20.MinimumWidth = 60;
            this.Column20.Name = "Column20";
            this.Column20.ReadOnly = true;
            this.Column20.SortMode = System.Windows.Forms.DataGridViewColumnSortMode.Automatic;
            this.Column20.UserTextNumericFormat = QMVnSoft.AppInstance.TextNumericFormat.Percent;
            this.Column20.Width = 60;
            // 
            // Column21
            // 
            this.Column21.DataPropertyName = "Do_Con_PT";
            dataGridViewCellStyle5.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleRight;
            this.Column21.DefaultCellStyle = dataGridViewCellStyle5;
            this.Column21.HeaderText = "Độ cồn";
            this.Column21.MinimumWidth = 60;
            this.Column21.Name = "Column21";
            this.Column21.ReadOnly = true;
            this.Column21.SortMode = System.Windows.Forms.DataGridViewColumnSortMode.Automatic;
            this.Column21.UserTextNumericFormat = QMVnSoft.AppInstance.TextNumericFormat.Percent;
            this.Column21.Width = 60;
            // 
            // Column14
            // 
            this.Column14.HeaderText = "Kệ nhập";
            this.Column14.MinimumWidth = 70;
            this.Column14.Name = "Column14";
            this.Column14.ReadOnly = true;
            this.Column14.Width = 70;
            // 
            // Column23
            // 
            this.Column23.DataPropertyName = "Ghi_Chu";
            this.Column23.HeaderText = "Ghi chú";
            this.Column23.MinimumWidth = 100;
            this.Column23.Name = "Column23";
            this.Column23.ReadOnly = true;
            this.Column23.Resizable = System.Windows.Forms.DataGridViewTriState.True;
            // 
            // Column22
            // 
            this.Column22.DataPropertyName = "So_Luong9";
            dataGridViewCellStyle6.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleRight;
            this.Column22.DefaultCellStyle = dataGridViewCellStyle6;
            this.Column22.HeaderText = "Số lượng";
            this.Column22.MinimumWidth = 80;
            this.Column22.Name = "Column22";
            this.Column22.ReadOnly = true;
            this.Column22.SortMode = System.Windows.Forms.DataGridViewColumnSortMode.Automatic;
            this.Column22.UserTextNumericFormat = QMVnSoft.AppInstance.TextNumericFormat.Quantity;
            this.Column22.Width = 80;
            // 
            // FormCTKHOLister
            // 
            this.CheckAccountingInvoice = false;
            this.ClientSize = new System.Drawing.Size(794, 532);
            this.Controls.Add(this.GridContainer);
            this.Name = "FormCTKHOLister";
            this.ShowPaymentButton = false;
            this.StoredProcedure = "Danh_So_CtKho";
            this.Controls.SetChildIndex(this.GridContainer, 0);
            this.GridContainer.Panel1.ResumeLayout(false);
            this.GridContainer.Panel2.ResumeLayout(false);
            this.GridContainer.ResumeLayout(false);
            ((System.ComponentModel.ISupportInitialize)(this.grdMaster)).EndInit();
            ((System.ComponentModel.ISupportInitialize)(this.grdDetail)).EndInit();
            this.ResumeLayout(false);
            this.PerformLayout();

        }

        protected override void OnAdd()
        {
            base.LocalFormEditor = new FormCTKHOEditor(base.AppInvoiceParameters);
            base.OnAdd();
        }

        protected override void OnCopy()
        {
            base.LocalFormEditor = new FormCTKHOEditor(base.AppInvoiceParameters);
            base.OnCopy();
        }

        protected override void OnDelete()
        {
            if (MessageBox.Show(AppInstance.DeleMessage, AppInstance.SoftwareName, MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
            {
                if ((base.MasterGridBrowser.SelectedRows != null) && (base.MasterGridBrowser.SelectedRows.Count <= 1))
                {
                    DataRow row = ((DataRowView) base.MasterGridBrowser.CurrentRow.DataBoundItem).Row;
                    if (!this.CheckInvoiceStatus(row["Stt"]))
                    {
                        return;
                    }
                    this.oMethod.Delete(AppInstance.UserName, row["Stt"]);
                    base.LocalMasterTable.Rows.Remove(row);
                }
                else
                {
                    this.oCanNotDelete = null;
                    string str = null;
                    int num = 0;
                    foreach (DataGridViewRow row2 in base.MasterGridBrowser.SelectedRows)
                    {
                        DataRow row3 = ((DataRowView) row2.DataBoundItem).Row;
                        if (this.CheckInvoiceStatus(row3["Stt"], ref str, ref num))
                        {
                            this.oMethod.Delete(AppInstance.UserName, row3["Stt"]);
                            base.LocalMasterTable.Rows.Remove(row3);
                        }
                        else
                        {
                            this.AddNotDeleteInvoice(row3["Ngay_Ct"], row3["So_Ct"], str);
                        }
                    }
                    if ((this.oCanNotDelete != null) && (this.oCanNotDelete.Rows.Count > 0))
                    {
                        new FormNotDeletes(base.AppInvoiceParameters.DeletedMessage(), this.oCanNotDelete).ShowDialog();
                    }
                }
                base.OnDelete();
            }
        }

        protected override void OnEdit()
        {
            base.LocalFormEditor = new FormCTKHOEditor(base.AppInvoiceParameters);
            base.OnEdit();
        }

        protected override void OnFillData()
        {
            base.LocalMasterTable = this.oMethod.GetMasterTable(AppInstance.Subsidiary, AppInstance.DaysFilter, this.id_Ngay_Ct1, this.id_Ngay_Ct2, this.is_So_Ct1, this.is_So_Ct2, base.InvoiceCode, this.is_Ma_Dt, this.is_Ma_Kho, this.is_Ma_Vt, this.is_Dien_Giai, this.is_Ma_Loai1, this.is_Ma_Loai2, this.is_Ma_Loai3, this.ii_FilterByUser, AppInstance.UserName, this.is_Ghi_Chu, this.ii_Posted, this.ii_Locked);
            base.OnFillData();
        }

        protected override void OnFilter()
        {
            FormCTKHOFilter filter = new FormCTKHOFilter();
            filter.Ngay_Ct1 = this.id_Ngay_Ct1;
            filter.Ngay_Ct2 = this.id_Ngay_Ct2;
            filter.So_Ct1 = this.is_So_Ct1;
            filter.So_Ct2 = this.is_So_Ct2;
            filter.Ma_Dt = this.is_Ma_Dt;
            filter.Ma_Kho = this.is_Ma_Kho;
            filter.Ma_Vt = this.is_Ma_Vt;
            filter.Dien_Giai = this.is_Dien_Giai;
            filter.Ghi_Chu = this.is_Ghi_Chu;
            filter.Ma_Loai1 = this.is_Ma_Loai1;
            filter.Ma_Loai2 = this.is_Ma_Loai2;
            filter.Ma_Loai3 = this.is_Ma_Loai3;
            filter.FilterByUser = this.ii_FilterByUser;
            filter.Posted = this.ii_Posted;
            filter.Locked = this.ii_Locked;
            filter.ShowDialog();
            if (filter.CheckAccepted)
            {
                this.id_Ngay_Ct1 = filter.Ngay_Ct1;
                this.id_Ngay_Ct2 = filter.Ngay_Ct2;
                this.is_So_Ct1 = filter.So_Ct1;
                this.is_So_Ct2 = filter.So_Ct2;
                this.is_Ma_Dt = filter.Ma_Dt;
                this.is_Ma_Kho = filter.Ma_Kho;
                this.is_Ma_Vt = filter.Ma_Vt;
                this.is_Dien_Giai = filter.Dien_Giai;
                this.is_Ghi_Chu = filter.Ghi_Chu;
                this.is_Ma_Loai1 = filter.Ma_Loai1;
                this.is_Ma_Loai2 = filter.Ma_Loai2;
                this.is_Ma_Loai3 = filter.Ma_Loai3;
                this.ii_FilterByUser = filter.FilterByUser;
                this.ii_Posted = filter.Posted;
                this.ii_Locked = filter.Locked;
                base.OnFilter();
            }
        }

        protected override void OnLock(bool pb_Locked)
        {
            if ((base.MasterGridBrowser.SelectedRows != null) && (base.MasterGridBrowser.SelectedRows.Count <= 1))
            {
                DataRow row = ((DataRowView) base.MasterGridBrowser.CurrentRow.DataBoundItem).Row;
                if (this.CheckInvoiceLock(row["Stt"], pb_Locked))
                {
                    row["Locked"] = pb_Locked;
                    base.LocalMasterRow["Locked"] = pb_Locked;
                }
            }
            else
            {
                this.oCanNotDelete = null;
                string str = null;
                foreach (DataGridViewRow row2 in base.MasterGridBrowser.SelectedRows)
                {
                    DataRow row3 = ((DataRowView) row2.DataBoundItem).Row;
                    if (this.CheckInvoiceLock(row3["Stt"], pb_Locked, ref str))
                    {
                        row3["Locked"] = pb_Locked;
                        if (base.LocalMasterRow["Stt"].Equals(row3["Stt"]))
                        {
                            base.LocalMasterRow["Locked"] = pb_Locked;
                        }
                    }
                    else
                    {
                        this.AddNotDeleteInvoice(row3["Ngay_Ct"], row3["So_Ct"], str);
                    }
                }
                if ((this.oCanNotDelete != null) && (this.oCanNotDelete.Rows.Count > 0))
                {
                    new FormNotDeletes(base.AppInvoiceParameters.LockedTitle(pb_Locked), this.oCanNotDelete).ShowDialog();
                }
            }
            base.OnLock(pb_Locked);
        }

        protected override void OnPost(int pi_Posted)
        {
            if ((base.MasterGridBrowser.SelectedRows != null) && (base.MasterGridBrowser.SelectedRows.Count <= 1))
            {
                DataRow row = ((DataRowView) base.MasterGridBrowser.CurrentRow.DataBoundItem).Row;
                if (this.CheckInvoicePost(row["Stt"], pi_Posted))
                {
                    row["Posted"] = pi_Posted;
                    base.LocalMasterRow["Posted"] = pi_Posted;
                }
            }
            else
            {
                this.oCanNotDelete = null;
                string str = null;
                int num = 0;
                foreach (DataGridViewRow row2 in base.MasterGridBrowser.SelectedRows)
                {
                    DataRow row3 = ((DataRowView) row2.DataBoundItem).Row;
                    if (this.CheckInvoicePost(row3["Stt"], pi_Posted, ref str, ref num))
                    {
                        row3["Posted"] = pi_Posted;
                        if (base.LocalMasterRow["Stt"].Equals(row3["Stt"]))
                        {
                            base.LocalMasterRow["Posted"] = pi_Posted;
                        }
                    }
                    else
                    {
                        this.AddNotDeleteInvoice(row3["Ngay_Ct"], row3["So_Ct"], str);
                    }
                }
                if ((this.oCanNotDelete != null) && (this.oCanNotDelete.Rows.Count > 0))
                {
                    new FormNotDeletes(base.AppInvoiceParameters.PostedTitle(pi_Posted), this.oCanNotDelete).ShowDialog();
                }
            }
            base.OnPost(pi_Posted);
        }

        internal override void OnResetControls()
        {
            if (!base.AppInvoiceParameters.BilingualUsed)
            {
                base.MasterGridBrowser.Columns[5].Visible = false;
            }
            if (base.InvoiceCode != "PWDC")
            {
                base.MasterGridBrowser.Columns[7].Visible = false;
            }
            if (!AppInstance.LocationCtrl)
            {
                base.DetailGridBrowser.Columns[4].Visible = false;
            }
            if (!AppInstance.LotNumberCtrl)
            {
                base.DetailGridBrowser.Columns[5].Visible = false;
            }
            if (!AppInstance.DeadLineCtrl)
            {
                base.DetailGridBrowser.Columns[6].Visible = false;
            }
            if (!AppInstance.QualityCtrl)
            {
                base.DetailGridBrowser.Columns[7].Visible = false;
            }
            if (!AppInstance.DampCtrl)
            {
                base.DetailGridBrowser.Columns[8].Visible = false;
            }
            if (!AppInstance.AlcoholCtrl)
            {
                base.DetailGridBrowser.Columns[9].Visible = false;
            }
            if (!AppInstance.LocationCtrl || (base.InvoiceCode != "PWDC"))
            {
                base.DetailGridBrowser.Columns[10].Visible = false;
            }
            base.OnResetControls();
        }

        internal override void OnShowMaster()
        {
            base.LocalMasterRow = this.oMethod.GetMasterDataRow(base.MasterInvoiceOrder);
            base.LocalDetailDataSet = this.oMethod.GetDetailDataSet(base.MasterInvoiceOrder);
            base.OnShowMaster();
        }
    }
}

